package seqlist.oj;

/**
 * @Author: yuisama
 * @Date: 2019/12/6 16:01
 * @Description:反转链表-引入额外空间版本
 */
public class Solution206 {
    public ListNode reverseList(ListNode head) {
        if (head == null || head.next == null) {
            return head;
        }
        ListNode newHead = new ListNode(head.val);
        while (head.next != null) {
            ListNode node = new ListNode(head.next.val);
            node.next = newHead;
            newHead = node;
            head = head.next;
        }
        return newHead;
    }
}
